import type { CreateOrderData } from '@/types/goods'
import { defineStore } from 'pinia'
import { ref } from 'vue'

// 定义 Store
export const useOrderStore = defineStore(
  'order',
  () => {
    // 订单信息
    const order = ref<CreateOrderData>()

    // 保存订单，登录时使用
    const setOrder = (val: CreateOrderData) => {
      order.value = val
    }

    // 记得 return
    return {
      order,
      setOrder,
    }
  },
  // TODO: 持久化
  {
    persist: {
      storage: {
        setItem(key, data) {
          uni.setStorageSync(key, data)
        },
        getItem(key) {
          return uni.getStorageSync(key)
        },
      },
    },
  },
)
